# -*- coding: utf-8 -*-
from . import base_dispatch
from . import dayahead_data
from . import dayahead_model
from ..solver import lp_solve1

class dayahead_dispatch(base_dispatch.base_dispatch):

    def __init__(self,micro_grid):
        super(dayahead_dispatch, self).__init__()
        self.dispatch_id = None

        self.lp_solve = lp_solve1.lp_solve1()

        self.micro_grid = micro_grid

        self.dayahead_data = dayahead_data.dayahead_data(micro_grid)

    # PV is the day ahead forecast of next day
    # load is the day ahead forecast of next day
    def run(self, pv, load, price):
        # specifically for pv, battery
        self.dayahead_data.update_load(load)

        self.dayahead_data.update_pv(pv)

        self.dayahead_data.update_price(price)

        # optimization model
        opt_model = dayahead_model.dayahead_model()

        opt_model.update_data(self.dayahead_data)

        # solving
        schedule = self.lp_solve.run(opt_model.optimize_model())

        return schedule
